<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="身份证号" prop="userSnum">
        <el-input
          v-model="queryParams.userSnum"
          placeholder="请输入患者身份证号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索身份证号</el-button>
<!--        <el-col :span="1.5">-->
<!--          <el-button-->
<!--            type="primary"-->
<!--            plain-->
<!--            icon="el-icon-plus"-->
<!--            size="mini"-->
<!--            @click="handleAdd"-->
<!--            v-hasPermi="['menzhen:user:add']"-->
<!--          >新增</el-button>-->
<!--        </el-col>-->
      </el-form-item>
    </el-form>

<!--    <el-row :gutter="10" class="mb8">-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['system:post:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['system:post:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          plain-->
<!--          icon="el-icon-delete"-->
<!--          size="mini"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--          v-hasPermi="['system:post:remove']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['system:post:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
<!--    </el-row>-->
    <el-table v-loading="loading" :data="postList">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="身份证号" align="center" prop="userSnum" />
      <el-table-column label="患者姓名" align="center" prop="userName" />
      <el-table-column label="患者电话" align="center" prop="userPhone" />
      <el-table-column label="性别" align="center" prop="userSex" :formatter="statusFormat" />
      <el-table-column label="生日" align="center" prop="userBrithday"/>
      <el-table-column label="患者年龄" align="center" prop="userAge" />
      <el-table-column label="地址信息" align="center" prop="userAddr" />

<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
<!--        <template slot-scope="scope">-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['system:post:edit']"-->
<!--          >修改</el-button>-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['system:post:remove']"-->
<!--          >删除</el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>

    <pagination
      v-show="total>1"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    /><br>
  <el-col :span="1.5">
      <el-button
        type="primary"
        plain
        icon="el-icon-plus"
        size="mini"
        @click="handleAdd"
        v-hasPermi="['menzhen:user:add']"
      >挂号收费</el-button>
    </el-col>

    <!-- 添加或修改岗位对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="900px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-col :span="12">
        <el-form-item label="身份证号" prop="userSnum" width="20px">
          <el-input width="20px" v-model="form.userSnum" placeholder="请输入患者身份证号" />
        </el-form-item>
        </el-col>
        <el-col :span="12">
        <el-form-item label="患者名称" prop="userName">
          <el-input v-model="form.userName" placeholder="请输入患者名称" />
        </el-form-item>
        </el-col>
        <el-col :span="12">
        <el-form-item label="患者电话" prop="userPhone">
          <el-input v-model="form.userPhone" placeholder="请输入患者电话" />
        </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="用户性别">
            <el-select v-model="form.userSex" placeholder="请选择">
              <el-option
                v-for="dict in sexOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
        <el-form-item label="出生日期" prop="userBrithday">
          <el-input v-model="form.userBrithday" placeholder="请输入患者出生日期" />
        </el-form-item>
        </el-col>
        <el-col :span="12">
        <el-form-item label="患者年龄" prop="userAge">
          <el-input v-model="form.userAge" placeholder="请输入患者年龄" />
        </el-form-item>
        </el-col>
        <el-col :span="12">
        <el-form-item label="地址信息" prop="userAddr">
          <el-input v-model="form.userAddr" placeholder="请输入患者地址" />
        </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="挂号费用">
            <el-select v-model="form.userMony" placeholder="请选择">
              <el-option
                v-for="dict in MonyOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
        <el-form-item label="流水编号" prop="userCode">
          <el-input v-model="form.userCode" placeholder="请输入流水编号" />
        </el-form-item>
        </el-col>
        <<el-col :span="12">
        <el-form-item label="挂号类型" prop="userMz">
          <el-input v-model="form.userMz" placeholder="请输入挂号类型" />
        </el-form-item>
      </el-col>
        <el-col :span="12">
          <el-form-item label="挂号时段">
            <el-select v-model="form.userSd" placeholder="请选择">
              <el-option
                v-for="dict in SdOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listPost, getPost, delPost, addPost, updatePost, exportPost } from "@/api/menzhen/menzhen";

export default {
  name: "Post",
  data() {
    return {
      // 遮罩层
      // loading: false,
      // 选中数组
      // ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 岗位表格数据
      postList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
        sexOptions: [],
        monyOptions: [],
        SdOptions: [],
      // 状态数据字典
      statusOptions: [],
        statusO:[],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 3,
        userCode: undefined,
        userName: undefined,
        userSd: undefined,
          menuType: "1",
        createTime: undefined,
        status: undefined,
        userSnum: undefined,
          userSex:0,
      },
      // 表单参数
      form: {},
      // 表单校验

    };
  },
  created() {

    this.getList();

      this.getDicts("menzhen_sex").then(response => {
          this.statusOptions= response.data;
      });
      this.getDicts("sys_user_sex").then(response => {
          this.sexOptions = response.data;
      });
      this.getDicts("sys_user_sd").then(response => {
          this.SdOptions = response.data;
      });
      this.getDicts("sys_user_mony").then(response => {
          this.MonyOptions = response.data;
      });
  },
  methods: {
    /** 查询岗位列表 */
    getList() {
      this.loading = true;
      listPost(this.queryParams).then(response => {
        this.postList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 岗位状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
      statusFormat(row, column) {
          return this.selectDictLabel(this.sexOptions, row.userSex);
      },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        userName: undefined,
        userCode: undefined,
        userMony: undefined,
        createTime: undefined,
        userMz: undefined,
        userSd: undefined,
        remark: undefined,
        userSex: 0
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    // handleSelectionChange(selection) {
    //   this.ids = selection.map(item => item.postId)
    //   this.single = selection.length!=1
    //   this.multiple = !selection.length
    // },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "增加患者信息";
    },
    // /** 修改按钮操作 */
    // handleUpdate(row) {
    //   this.reset();
    //   const postId = row.postId || this.ids
    //   getPost(postId).then(response => {
    //     this.form = response.data;
    //     this.open = true;
    //     this.title = "修改岗位";
    //   });
    // },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.postId != undefined) {
            updatePost(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPost(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    // handleDelete(row) {
    //   const postIds = row.postId || this.ids;
    //   this.$confirm('是否确认删除岗位编号为"' + postIds + '"的数据项?', "警告", {
    //       confirmButtonText: "确定",
    //       cancelButtonText: "取消",
    //       type: "warning"
    //     }).then(function() {
    //       return delPost(postIds);
    //     }).then(() => {
    //       this.getList();
    //       this.msgSuccess("删除成功");
    //     })
    // },
    /** 导出按钮操作 */
    // handleExport() {
    //   const queryParams = this.queryParams;
    //   this.$confirm('是否确认导出所有岗位数据项?', "警告", {
    //       confirmButtonText: "确定",
    //       cancelButtonText: "取消",
    //       type: "warning"
    //     }).then(function() {
    //       return exportPost(queryParams);
    //     }).then(response => {
    //       this.download(response.msg);
    //     })
    // }
  }
};
</script>

